﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Asah.SiteWorx.SiteMap;
using Telerik.Web.UI;

public partial class App_Common_UserControls_Navigation : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            LoadMenuItems();

    }

    private void LoadMenuItems()
    {
        RadMenuItem menuItem;

        LinkedList<PageInfo> menuList = Asah.SiteWorx.Site.GetSite().NavigationMenu;
        foreach (PageInfo menu in menuList)
        {
            menuItem = new RadMenuItem();
            menuItem.Text = menu.MenuText;
            menuItem.ToolTip = menu.MenuHoverText;
            menuItem.NavigateUrl = menu.Url;
            LoadSubMenuItems(menu.ChildPages,ref menuItem);
            radNavigationMenu.Items.Add(menuItem);
        }

    }

    private void LoadSubMenuItems(LinkedList<PageInfo> menuList, ref RadMenuItem menuItem)
    {
        RadMenuItem subMenuItem;
        foreach (PageInfo menu in menuList)
        {
            subMenuItem = new RadMenuItem();
            subMenuItem.Text = menu.MenuText;
            subMenuItem.ToolTip = menu.MenuHoverText;
            subMenuItem.NavigateUrl = menu.Url;
            LoadSubMenuItems(menu.ChildPages,ref subMenuItem);
            menuItem.Items.Add(subMenuItem);
        }
    }
  
}
